package main;

import main.Game.Player;

/**
 * 玩家控制类
 * @author svitter
 *
 */
public class Controler_player {

	public static int max_player = 4;		/** 限制最大的玩家人数 */
	
	Player[]			player;
	int 				num; 				/** 当前玩家人数 */
	private int 		turn; 				/** 获取当前turn */
	
	public Controler_player(int _num) {
		this.turn = 0;
		this.num = _num;
		this.player = new Player[4];
		_playInit();
	}
	
	public Controler_player(int _playernum, int turn) {
		this.turn = turn;
		this.num = _playernum;
		this.player = new Player[4];
		_playInit();
	}
	
	private void _playInit() {
		for(int i = 0; i < 4; i++) {
			player[i] = new Player(i);
		}
	}
	
	/**
	 * 重置玩家信息
	 */
	public void reset() {
		this.turn = 0;
		this.player = new Player[4];
		_playInit();
	}
	
	/**
	 * 依据编号，获取玩家信息
	 * @param uid
	 * @return
	 */
	public Player no(int uid) {
		//TODO
		return player[uid];
	}
	
	/**
	 * @return 玩家编号
	 */
	public int Turn() {
		return turn;
	}
	
	/**
	 * 轮到下一个玩家
	 * @return
	 */
	public int next() {
		return turn = (turn + 1) % num;
	}

	/**
	 * 依据玩家id获取玩家名
	 * @param id
	 * @return name
	 */
	public String name(int id) {
		return player[id].name;
	}
	
	/**
	 * 判断是否结束
	 * @return
	 */
	public boolean end() {
		int n = 0;
		for(int i = 0; i < num; i++)
		{
			if(player[i].lose)
				continue;
			n++;
		}
		if(n == 1)
			return true;
		else
			return false;
	}
	
	/**
	 * 获取胜利玩家　编号
	 * @return
	 */
	public int winnerNum() {
		if(end())
		{
			for(int i = 0;  i < num; i++)
			{
				if(!player[i].lose)
					return i;
			}
		}
		return -1;
	}
}
